package com.example.tedtalksimproved;

import com.example.tedtalksimproved.cache.MyVolley;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

public class VideoGridFragment extends Fragment {
	
    private GridView mGridView;
	
    @Override
	    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	        View view = inflater.inflate(R.layout.activity_grid, container, false);

	        // Store a pointer to the GridView that powers this grid fragment.
	        mGridView = (GridView) view.findViewById(R.id.gridview);

	        return view;
	    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Activity activity = getActivity();
        Log.d("GridActivity",
				"Made it here");
        mGridView.setAdapter(new ImageAdapter(getActivity()));
	    Log.d("GridActivity",
				"Made it here 11111111111111111");
	    mGridView.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
				Intent detailIntent = new Intent(getActivity(), VideoDetailActivity.class);
				detailIntent.putExtra(VideoDetailFragment.ARG_ITEM_ID, position+"");
				startActivity(detailIntent);
	        }
	    });
    }
}
